﻿#include <iostream>
#include <windows.h>
using namespace std;

class Date {
private:
	int year;
	int month;
	int date;

public:
	void Init(int y, int m, int d) {
		year = y;
		month = m;
		date = d;
	}

	int getYear() { return year; }
	void setYear(int y) { year = y; }

	int getMonth() { return month; }
	void setMonth(int m) { month = m; }

	int getDate() { return date; }
	void setDate(int d) { date = d; }

	void display() {
		cout << year << "年" << month << "月" << date << "日";
	}

	// 正确定义calWeekday函数
	int calWeekday() {
		int y = year, m = month, d = date;
		if (m == 1 || m == 2) {
			m += 12;
			y--;
		}
		int weekday = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400 + 1) % 7;
		if (weekday < 0) weekday += 7;
		return weekday;
	}
};

int main() {
	system("chcp 936 > nul");

	Date myDate;
	myDate.Init(2025, 11, 15);

	myDate.display();
	cout << " 是星期";
	int weekday = myDate.calWeekday();  // 正确调用类成员函数
	const char* weekStr[7] = { "日", "一", "二", "三", "四", "五", "六" };
	cout << weekStr[weekday] << endl;

	myDate.setYear(2024);
	myDate.setMonth(1);
	myDate.setDate(1);
	myDate.display();
	cout << " 是星期";
	weekday = myDate.calWeekday();  // 正确调用类成员函数
	cout << weekStr[weekday] << endl;

	system("pause");
	return 0;
}